package com.ruoyi.school.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.school.domain.PacJournalsType;
import com.ruoyi.school.domain.PacReslutLevel;
import com.ruoyi.school.service.PacJournalsTypeService;
import com.ruoyi.school.mapper.PacJournalsTypeMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author jeremylin
* @description 针对表【pac_journals_type(学术成果等级)】的数据库操作Service实现
* @createDate 2025-07-10 23:06:48
*/
@Service
public class PacJournalsTypeServiceImpl extends ServiceImpl<PacJournalsTypeMapper, PacJournalsType>
    implements PacJournalsTypeService{

    @Override
    public List<PacJournalsType> getList(PacJournalsType rereslutLevel) {
        List<PacJournalsType> list = lambdaQuery().list();

        return list;
    }

    @Override
    public PacJournalsType getDetails(PacJournalsType rereslutLevel) {
        if (rereslutLevel.getId() == null) {
            throw new BaseException("id不能为空");
        }
        PacJournalsType one = lambdaQuery().eq(PacJournalsType::getId, rereslutLevel.getId()).one();

        return one;
    }

    @Override
    public boolean add(PacJournalsType rereslutLevel) {
        if (save(rereslutLevel)) {
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(PacJournalsType rereslutLevel) {
        if (updateById(rereslutLevel)) {
            return true;
        }
        return false;
    }

    /**
     *  1、删除的时候 需要先校验 改类型是否被其他的数据关联了，如果关联了，则不能删除
     * @param rereslutLevel
     * @return
     */
    @Override
    public boolean delete(PacJournalsType rereslutLevel) {
//        int count = academicOutputService.countByLevel(rereslutLevel.getId());
//        if (count > 0) {
//            throw new BaseException("该类型被申请关联，不能删除");
//        }
        removeById(rereslutLevel);

        return true;
    }

    @Override
    public List<PacJournalsType> getAllList(PacJournalsType rereslutLevel) {
        List<PacJournalsType> list = lambdaQuery().list();
        return list;
    }

    /**
     * 根据成果类型id查询
     *
     * @param resultTypeIds
     * @return
     */
    @Override
    public List<PacJournalsType> selectByResultTypeIds(List<Long> resultTypeIds) {
        if(resultTypeIds.isEmpty()){
            return new ArrayList<>();
        }
        List<PacJournalsType> list = lambdaQuery().in(PacJournalsType::getId, resultTypeIds).list();

        return list;
    }

    @Override
    public PacJournalsType selectByName(String resultTypeName) {
        PacJournalsType one = lambdaQuery().eq(PacJournalsType::getResName, resultTypeName).one();
        return one;
    }
}




